package com.sl.au.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.sl.au.entity.Account;
import com.sl.au.entity.EXDEHostToAccountStatistics;
import com.sl.au.service.EXDEPaidPartsRepairsService;

/**
 * 片区-备件维修到款统计控制器
 * @author yry
 * 2017-02-20
 */
@RestController
@RequestMapping(value="/ui/paidPartsRepairs")
public class PaidPartsRepairsController extends BaseController{
	
	@Autowired
	EXDEPaidPartsRepairsService exdePaidPartsRepairsService;
	
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(){
        ModelAndView modelAndView=createLayoutView("paymentSearch/paidPartsRepairs");
        Account a = this.getMyAccount();
		String userId =a.getUser().getId();
		modelAndView.addObject("userId",userId);
		return modelAndView;
    }
    
    /*
     * 查询片区-备件维修到款
     */
    @RequestMapping(value = "/getMyTrance", method = RequestMethod.GET)
	public Map<String,Object> getMyTrance(HttpServletRequest request) {
		Map<String,Object> map = new HashMap<String,Object>();
		Map<String,String> condition = new HashMap<String,String>();
		Account a = this.getMyAccount();
		//String userId = a.getUser().getId();
		String sSuperior = a.getUser().getSaleArea().getSuperior();//部门
		//String sSuperior = "销售处";
		String beginPaidDate = request.getParameter("beginPaidDate");//付款开始时间
		String endPaidDate = request.getParameter("endPaidDate");//付款结束时间
		String type = request.getParameter("type");
		List<EXDEHostToAccountStatistics> users = null;
        //condition.put("userId", userId);
		condition.put("sSuperior", sSuperior);
        condition.put("beginPaidDate", beginPaidDate);
        condition.put("endPaidDate", endPaidDate);
        condition.put("type", type);
		users = exdePaidPartsRepairsService.getMyPage(condition);
        long count = users.size();
		
		map.put("data", users);
		map.put("draw", request.getParameter("draw"));
		map.put("recordsFiltered", count);
		map.put("recordsTotal", count);
		return map;
	}
}
